#include "tcpip_adapter.h"
#include "esp_err.h"

int SetStaticIp(char *ip, char *netmask, char *gw)
{
    esp_netif_ip_info_t ip_info;
    esp_netif_t *eth_netif = esp_netif_get_handle_from_ifkey("ETH_DEF");

    if (!eth_netif) {
        return ESP_ERR_INVALID_STATE;
    }

    ip_info.ip.addr = ipaddr_addr(ip);
    ip_info.netmask.addr = ipaddr_addr(netmask);
    ip_info.gw.addr = ipaddr_addr(gw);

    esp_err_t ret = esp_netif_dhcpc_stop(eth_netif);
    if (ret != ESP_OK && ret != ESP_ERR_ESP_NETIF_DHCP_ALREADY_STOPPED) {
        return ret;
    }
    ret = esp_netif_set_ip_info(eth_netif, &ip_info);
    return ret;
}